﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Forget.Data;
using System.Data;
using System.Data.SqlClient;

namespace Forget.HRBLL.Model
{
    public partial class User
    {
        private static readonly string ADDUSERINFO = "HR_AddUserInfo";
        private static readonly string EDITUSERINFO = "HR_EditUserInfo";
        private static readonly string DELUSERINFO = "HR_DelUserInfo";


        #region Properties
        /// <summary>
        /// 用户唯一编号，由hr创建
        /// </summary>
        [DataParam(20, SqlDbType.NVarChar)]
        public string NumberID { get; set; }

        /// <summary>
        /// 用户登录名
        /// </summary>
        [DataParam(20, SqlDbType.NVarChar)]
        public string UserName { get; set; }

        [DataParam(50, SqlDbType.NVarChar)]
        public string PassWord { get; set; }

        /// <summary>
        /// 用户邮箱地址
        /// </summary>
        [DataParam(200, SqlDbType.NVarChar)]
        public string Email { get; set; }

        /// <summary>
        /// 用户电话
        /// </summary>
        [DataParam(20, SqlDbType.NVarChar)]
        public string Phone { get; set; }
        /// <summary>
        /// 用户真实姓名
        /// </summary>
        [DataParam(200, SqlDbType.NVarChar)]
        public string Name { get; set; }
        #endregion

        

        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="numberID">员工编号</param>
        /// <param name="userName">用户登录名</param>
        /// <param name="email">邮箱地址</param>
        /// <param name="phone">电话</param>
        /// <param name="name">真实姓名</param>
        /// <returns></returns>
        public static bool AddUserInfo(User user)
        {
            List<SqlParameter> parms = Convert<SqlParameter>.ObjectToParms(user);
            try
            {
                if (DataAccess.ExecuteNonQuery(CommandType.StoredProcedure, ADDUSERINFO, parms.ToArray()) > 0)
                    return true;
            }
            catch (Exception ex)
            {
                Log.WriteLog("BU.AddUserInfo", ex.Message, ex.StackTrace);
            }

            return false;
        }

        /// <summary>
        /// 编辑用户信息
        /// </summary>
        /// <param name="numberID">员工编号</param>
        /// <param name="email">邮件地址</param>
        /// <param name="phone">电话号码</param>
        /// <param name="name">真实姓名</param>
        /// <returns>修改成功返回true，否则返回false</returns>
        public static bool EditUserInfo(User user)
        {
            List<SqlParameter> parms = Convert<SqlParameter>.ObjectToParms(user);
            try
            {
                if (DataAccess.ExecuteNonQuery(CommandType.StoredProcedure, EDITUSERINFO, parms.ToArray()) > 0)
                    return true;
            }
            catch (Exception ex)
            {
                Log.WriteLog("BU.EditUserInfo", ex.Message, ex.StackTrace);
            }
            return false;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static bool DelUserInfo(User user)
        {
            List<SqlParameter> parms = Convert<SqlParameter>.ObjectToParms(user);
            try
            {
                if (DataAccess.ExecuteNonQuery(CommandType.StoredProcedure, DELUSERINFO, parms.ToArray()) > 0)
                    return true;
            }
            catch (Exception ex)
            {
                Log.WriteLog("BU.DelUserInfo", ex.Message, ex.StackTrace);
            }
            return false;
        }
    }
}
